#include "mouse.h"
#include <QDebug>
#include <QMouseEvent>
#include <QEvent>
#include <QPoint>

mouse::mouse(QWidget *parent)
	: QLabel{parent}
{
	this->setMouseTracking(true);
}

void mouse::mousePressEvent(QMouseEvent *event)
{
	//qDebug() << "MousePressEvent:" << event->button() << event->pos() << event->globalPos();
	QPointF point=event->position();
	//QPointF Point=event->globalPosition();
	int x=point.x();
	int y=point.y();
	if(event->button() == Qt::MouseButton::LeftButton){
		qDebug() << "左键按下： x=" << x << " y=" << y ;
	}else if(event->button() == Qt::MouseButton::RightButton){
		qDebug() << "右键按下： x=" << x << " y=" << y ;
	}
}

void mouse::mouseReleaseEvent(QMouseEvent *event)
{
	//qDebug() << "MouseRealseEvent:" << event->button() << event->pos() << event->globalPos();
	QPointF point=event->position();
	int x=point.x();
	int y=point.y();
	if(event->button() == Qt::MouseButton::LeftButton){
		qDebug() << "左键释放： x=" << x << " y=" << y;
	}else if(event->button() == Qt::MouseButton::RightButton){
		qDebug() << "右键释放： x=" << x << " y=" << y ;
	}
}

void mouse::mouseMoveEvent(QMouseEvent *event)
{
	QPointF point=event->position();
	qDebug() << "鼠标移动: x=" << point.x() << " y="<< point.y();
}
